package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Scanner;

public class LoginDemo {
    public static void main(String[] args) {
        System.out.println("请输入用户名和密码");
        Scanner sc = new Scanner(System.in);
        try (Connection connection = DBUtil.getConnection();){
            Statement statement = connection.createStatement();
            String sql = "select id,username,password,nickname,age from user where username='"+sc.next()+" 'and password='"+sc.next()+"' ";
            ResultSet resultSet = statement.executeQuery(sql);//将查询结果集保存到resultSet中
           if (resultSet.next()){//判断用户名密码是否正确
               System.out.println("登录成功");
            } else {
                System.out.println("用户名或密码错误");
           }


        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
